﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Waker.Common;

namespace Waker.Cards
{
    public partial class FormStaffNoSwipe : Base.FormBaseToolBar
    {
        public FormStaffNoSwipe()
        {
            InitializeComponent();
        }

        private void FormStaffNoSwipe_Load(object sender, EventArgs e)
        {
            dteBeginDate.DateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            dteEndDate.DateTime = dteBeginDate.DateTime.AddMonths(1).AddSeconds(-1);
            var dtSite = new BAL.BAL_Cards().GetAllDepartment();
            ckbListSubContractor.Properties.DataSource = dtSite;
            FormRefresh();
        }
        public override void FormRefresh()
        {
            DateTime endDate = DateTime.Parse(dteEndDate.DateTime.ToShortDateString()).AddDays(1).AddSeconds(-1);
            var dt = new BAL.BAL_Records().EmployeeNoWipeSeach(
              dteBeginDate.DateTime
                , endDate
                , ckbListSubContractor.EditValue == null ? string.Empty : ckbListSubContractor.EditValue.ToString().Trim()
                , txtEmp_Name.Text.Trim()
                , txtEmp_No.Text.Trim()
                , txtEmp_IDCard.Text.Trim()
                );
            this.gridControl1.DataSource = dt;
            if (gridView1.GroupCount > 0)
                gridView1.ExpandGroupRow(gridView1.FocusedRowHandle, false);
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            FormRefresh();
        }
        protected override void FormAdd()
        {
            if (gridView1.FocusedRowHandle < 0)
                return;
            var dr = gridView1.GetFocusedDataRow();
            if (dr == null)
                return;
            if (!UI.ShowOKCancelReturnBool(string.Format("确定要将[{0}]设置为离职员工?", dr["Emp_Name"])))
            {
                return;
            }
            var isok = new BAL.BAL_Cards().SetEmployeeLeave(dr["Emp_ID"].ToString(), true);
            if (isok)
            {
                UI.ShowInfo("离职设置成功");
                FormRefresh();
            }
            else
                UI.ShowError("离职设置失败");
        }
    }
}
